﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LWrap.Index;
using LWrap.IndexSource;
using LWrap.Search;
using LWrap.IndexSync;
namespace Client
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private const string INDEX_PATH = @"C:\IndexPath";
        private void button1_Click(object sender, EventArgs e)
        {
            IndexJob indexJob = new IndexJob();
            DBDataSource dbDataSource = new DBDataSource();

            dbDataSource.DataToIndex = this.CreateTestData();
            indexJob.IndexSource = dbDataSource;
            indexJob.CreateNewIndex = true;
            indexJob.IndexFilePath = INDEX_PATH;
            indexJob.ExecuteIndex();
        }

        private DataTable CreateTestData()
        {
            DataTable table = new DataTable();
            DataColumn col1 = new DataColumn("ID");
            DataColumn col2 = new DataColumn("Name");
            DataColumn col4 = new DataColumn("Description");
            DataColumn col7 = new DataColumn("Remarks");

            col1.DataType = System.Type.GetType("System.String");
            col2.DataType = System.Type.GetType("System.String");
            col4.DataType = System.Type.GetType("System.String");
            col7.DataType = System.Type.GetType("System.String");

            table.Columns.Add(col1);
            table.Columns.Add(col2);
            table.Columns.Add(col4);
            table.Columns.Add(col7);

            DataRow row = table.NewRow();
            row[col1] = "1100";
            row[col2] = "Computer Set";
            row[col4] = "New computer set";
            row[col7] = "Purchased on July 30,2008";
            table.Rows.Add(row);

            DataRow row1 = table.NewRow();
            row1[col1] = "1200";
            row1[col2] = "C# Books";
            row1[col4] = "CLR via C#";
            row1[col7] = "Purchased on July 27 2010";

            table.Rows.Add(row1);
            return table;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SearchWord searchWord = new SearchWord();
            List<string> fields = new List<string>();
            fields.Add("DocContent");
            fields.Add("DocName");
            fields.Add("ModifiedDate");
            searchWord.Search("DocContent:Lucene OR ID:printing", @"C:\IndexPathFiles\Source", "ID", fields);
        }

        private void btnFileIndex_Click(object sender, EventArgs e)
        {
            IndexJob indexJob = new IndexJob();
            FileDataSource fileDataSource = new FileDataSource();

            fileDataSource.FolderToIndex = @"C:\Sony\Working Project\Lucene.NET\TestFilesToIndex";
            indexJob.IndexSource = fileDataSource;
            indexJob.CreateNewIndex = true;
            indexJob.IndexFilePath = @"C:\IndexPathFiles\Source";
            indexJob.ExecuteIndex();

            SearchWord searchWord = new SearchWord();
            List<string> fields = new List<string>();
            fields.Add("ModifiedDate");
            fields.Add("DocName");
            searchWord.Search("DocBytes:documents ", INDEX_PATH, "ID", fields);
        }

        private void btnSync_Click(object sender, EventArgs e)
        {
            DifferentialSync diffSync = new DifferentialSync();
            diffSync.SyncFiles(@"C:\IndexPathFiles\Source", @"C:\IndexPathFiles\Destination");
        }
    }
}
